package org.yuning.cloud.common.web;

import lombok.Builder;
import lombok.Data;
import lombok.ToString;

/**
 * @author zhangzz
 * @email 291110369@qq.com
 * @date 2023/11/9 16:44
 * @description
 **/
@Data
@Builder
@ToString
public class JsonResult<T> {

    private int code;
    private String message;
    private T data;

    public static <T> JsonResult<T> success(T data) {
        return (JsonResult<T>) JsonResult.builder().code(200).message("请求成功").data(data).build();
    }

    public static <T> JsonResult<T> success(T data, String message) {
        return (JsonResult<T>) JsonResult.builder().code(200).message(message).data(data).build();
    }

    public static <T> JsonResult<T> fail(String message) {
        return (JsonResult<T>) JsonResult.builder().code(500).message(message).data(null).build();
    }

    public static <T> JsonResult<T> fail(int code, String message) {
        return (JsonResult<T>) JsonResult.builder().code(code).message(message).data(null).build();
    }

    public static <T> JsonResult<T> fail(int code, String message, T data) {
        return (JsonResult<T>) JsonResult.builder().code(code).message(message).data(data).build();
    }

}
